package com.cbh.amadeus.server.config;

import com.cbh.amadeus.server.core.Publisher;
import com.cbh.amadeus.server.provider.component.PublisherComponent;
import com.cbh.amadeus.server.provider.tool.AckResultModelTool;
import com.cbh.amadeus.server.provider.tool.impl.DefaultAckResultModelTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ChenBiHui
 * @date 2025/4/27
 */
@Slf4j
@Configuration
@ConditionalOnBean({PublisherConfig.class})
public class PublisherAutoConfiguration {

    @Bean
    public PublisherComponent publisherComponent() {
        PublisherComponent publisherComponent = new PublisherComponent();
        log.info("===== PublisherComponent initial finish =====");
        return publisherComponent;
    }

    @Bean
    public Publisher publisher() {
        Publisher publisher = new Publisher();
        log.info("===== Publisher initial finish =====");
        return publisher;
    }

    @Bean
    @ConditionalOnMissingBean(AckResultModelTool.class)
    public AckResultModelTool ackModelTool() {
        AckResultModelTool ackResultModelTool = new DefaultAckResultModelTool();
        log.info("===== AckResultModelTool initial finish =====");
        return ackResultModelTool;
    }
}
